package com.lzt.yijian.mvp.module;

import android.content.Context;
import android.os.CountDownTimer;

import com.lzt.yijian.R;
import com.lzt.yijian.mvp.base.BaseModel;
import com.lzt.yijian.mvp.view.activity.SplashView;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class SplashModuleImpl extends BaseModel implements SplashModule {
    @Override
    public void checkLogin(final Context context, final SplashView splashView) {
        CountDownTimer timer = new CountDownTimer(2 * 1000 + 300, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                DecimalFormat decimalFormat = new DecimalFormat(".00");
                String secondStringUntilFinished = decimalFormat.format(((float) millisUntilFinished / 1000));
                BigDecimal secondUntilFinished = new BigDecimal(secondStringUntilFinished)
                        .setScale(0, BigDecimal.ROUND_HALF_UP);
                String skip = String.format(context.getString(R.string.click_to_skip),
                        secondUntilFinished.toBigInteger().intValue());
                splashView.onDownTimeDone(skip);
            }

            @Override
            public void onFinish() {
                splashView.onCheckLoginDone(true);
            }
        };
        timer.start();
    }
}
